package com.qidian.mes.md.service.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.qidian.mes.md.mapper.MaterialBOMMapper;
import com.qidian.mes.md.service.MaterialBOMService;
import com.qidian.mes.pojo.MaterialBOM;
import com.qidian.mes.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: CoolPro
 * @Description:
 * @Time: 2024-04-08 15:22
 **/
@Service
public class MaterialBOMServiceImpl implements MaterialBOMService {
    @Autowired
    private MaterialBOMMapper materialBOMMapper;
    @Override
    public QdResult findByOrderId(Integer orderId) {
        return QdResult.success(materialBOMMapper.findByOrderId(orderId));
    }

    @Override
    public QdResult addMaterialBOM(MaterialBOM materialBOM, Integer productId) {
        materialBOMMapper.add(materialBOM,productId);
        return QdResult.success();
    }

    //删除BOM信息
    @Override
    public QdResult deleteMaterialBOM(String data) {
        JSONObject jsonObject = JSON.parseObject(data);
        materialBOMMapper.delete(jsonObject.getInteger("matId"), jsonObject.getInteger("productId"),jsonObject.getInteger("orderId"));
        return QdResult.success();
    }

    //修改BOM信息
    @Override
    public QdResult updateMaterialBOM(MaterialBOM materialBOM, Integer productId) {
        materialBOMMapper.update(materialBOM,productId);
        return QdResult.success();
    }





}
